﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using EvidenceLib.Case;
using NHibernate;

namespace EvidenceService.Core
{
    public class BillSerialNoService
    {
        private ISession mSession;
        public BillSerialNoService(ISession session)
        {
            this.mSession = session;
        }

        public string GetNextSerialNo(BillTypeEnum billType)
        {
            int billDate = int.Parse(DateTime.Now.ToString("yyMMdd"));

            IDbCommand cmd = this.mSession.Connection.CreateCommand();

            cmd.CommandText = "Ev_GetNextBillSerialNo";

            cmd.CommandType = CommandType.StoredProcedure;

            IDataParameter p1 = cmd.CreateParameter();
            p1.ParameterName = "@billType";
            p1.DbType = DbType.Int32;
            p1.Value = billType;
            cmd.Parameters.Add(p1);

            IDataParameter p2 = cmd.CreateParameter();
            p2.ParameterName = "@billDate";
            p2.DbType = DbType.Int32;
            p2.Value = billDate;
            cmd.Parameters.Add(p2);


            string serialNo = cmd.ExecuteScalar().ToString();

            return serialNo;
        }

    }
}
